home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / cl0588.zip / DESKTOP.C < prev    next >
Text File  |  1988-01-21  |  1KB  |  67 lines

  1. /*.t|Clist demonstration using K&R pages 74-79*//*.function .author Kernighan & Ritchie*/
  2. /* A $2,000 desktop calculator that isn't even programmable! */
  3. /* This listing produced using the following command line:
  4.    CL -G -H -C -PBI DESKTOP
  5. */
  6.  
  7. /* .noincl              Don't include the (long) standard headers */
  8. #include <stdio.h>
  9. #include <math.h>
  10. /* .incl                Include the other files */
  11.  
  12. #define MAXOP   20
  13. #define NUMBER  '0'
  14. #define TOOBIG  '9'
  15.  
  16. #include <stack.c>
  17. #include <getop.c>
  18. #include <getch.c>
  19.  
  20. main()
  21. {
  22.   int     type;
  23.   char    s[MAXOP];
  24.   double  op2, atof(), pop(), push();
  25.  
  26.   while ((type = getop(s,maxop)) != EOF) {
  27.  
  28.     switch (type) {
  29.  
  30.     case NUMBER:
  31.          push(atof(s));
  32.          break;
  33.     case '+':
  34.          push(pop() + pop());
  35.          break;
  36.     case '*':
  37.          push(pop() * pop());
  38.          break;
  39.     case '-':
  40.          op2 = pop();
  41.          push(pop() - op2);
  42.          break;
  43.     case '/':
  44.          op2 = pop();
  45.          if (op2 != 0.0)
  46.              push(pop() / op2);
  47.          else
  48.              printf("Zero divisor popped\n");
  49.          break;
  50.     case '=':
  51.          printf("\t%f\n",push(pop()));
  52.          break;
  53.     case 'c':
  54.          clear();
  55.          break;
  56.     case TOOBIG:
  57.          printf("%.20s ... is too long\n");
  58.          break;
  59.     default:
  60.          printf("unknown command %c\n",type);
  61.          break;
  62.    }
  63. }
  64.  
  65. /* end of program, desktop.c */
  66.  
  67.